﻿using System;
using System.Threading;

namespace EventDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Cat cat = new Cat();
            Mouse mouse = new Mouse("米奇", "黑色", cat);
            cat.CatComing("加菲猫", "黄色");
        }
    }
    public class Cat
    {
        public string Name { get; set; }
        public string Cololr { get; set; }


        public void CatComing(string name,string color)
        {

            Console.WriteLine($"{this.Cololr=color}的{this.Name=name} 过来啦！！！");
            if (catcome != null)
                catcome();
        }
        public event Action catcome;
    }
    
    public class Mouse
    {
        public string Name { get; set; }
        public string Cololr { get; set; }
        public Mouse(string name,string color,Cat cat)
        {
            this.Name = name;
            this.Cololr = color;
            cat.catcome += this.Run;        

        }
        public void Run()
        {
            Console.WriteLine($"{this.Cololr}的{this.Name}看见后跑了");
        }
    }
}
